#include<bits/stdc++.h> #define rep(i, x, y) for (int i = x; i <= y; i++) usingnamespacestd;
constint N = 2e5 + 10; int n, m, K; int degt[N], degs[N], dt[N], ds[N], ans[N], id[N], tot; structedge {int x, y; }e[N]; vector<int> gt[N], gs[N]; queue<int> q; multiset<int> s; multiset<int>::iterator it;
intmain(){ cin >> n >> m >> K; rep(i, 1, m) { int x, y; scanf("%d%d", &x, &y); e[i].x = x, e[i].y = y; degt[y]++, degs[x]++; gt[x].push_back(y), gs[y].push_back(x); } rep(i, 1, n) if (!degt[i]) q.push(i); while (q.size()) { int x = q.front(); q.pop(); id[++tot] = x; for (int i = 0; i < gt[x].size(); i++) { int y = gt[x][i]; dt[y] = max(dt[y], dt[x] + 1); if (!(--degt[y])) q.push(y); } } rep(i, 1, n) if (!degs[i]) q.push(i); while (q.size()) { int x = q.front(); q.pop(); for (int i = 0; i < gs[x].size(); i++) { int y = gs[x][i]; ds[y] = max(ds[y], ds[x] + 1); if (!(--degs[y])) q.push(y); } }
rep(i, 1, n) s.insert(ds[i]); rep(o, 1, n) { int x = id[o]; s.erase(s.find(ds[x])); for (int i = 0; i < gs[x].size(); i++) { int y = gs[x][i]; s.erase(s.find(ds[x] + 1 + dt[y])); } ans[x] = *s.rbegin(); s.insert(dt[x]); for (int i = 0; i < gt[x].size(); i++) { int y = gt[x][i]; s.insert(dt[x] + 1 + ds[y]); } }
#include<bits/stdc++.h> #define rep(i, x, y) for (int i = x; i <= y; i++) usingnamespacestd;
typedeflonglong ll; constint N = 1e6 + 10; ll n, P; ll mark[N], p[N], tot, cnt[N];
voidsieve(int n){ rep(i, 2, n) { if (!mark[i]) p[++tot] = i, cnt[i] = 1; for (int j = 1; j <= tot && i * p[j] <= n; j++) { mark[i * p[j]] = 1; if (i % p[j] == 0) break; } } rep(i, 2, n) cnt[i] += cnt[i - 1]; }
ll dfs(ll x, ll t){ if (t > tot || x * p[t] > n) return1; if (x * p[t] * p[t] > n) return cnt[min(P, n / x)] - t + 2; // 优秀的剪枝们 ll ret = dfs(x, t + 1); for (; x * p[t] <= n; ) { x *= p[t]; ret += dfs(x, t + 1); x *= p[t]; } return ret; }